<template>
    <table class="table-bordered" border="1">
        <tr>
            <td>真实姓名</td>
            <td><input v-model="info.name" type="text" ></td>
        </tr>
        <tr>
            <td>性别</td>
            <td>
                <input v-model="info.sex" type="radio" name="sex" value="true" checked>男
                <input v-model="info.sex"  type="radio" name="sex" value="false">女
            </td>
        </tr>
        <tr>
            <td>年收入</td>
            <td><input v-model="info.incomes" type="text"></td>
        </tr>
        <tr>
            <td>身份证</td>
            <td><input v-model="info.idCard" type="text" @change="showw"></td>
        </tr>
        <tr>
            <td>出生日期</td>
            <td><input v-model="info.birthday" type="date" ></td>
        </tr>
       
        <tr>
            <td>用户类型</td>
            <td>
                <select v-model="info.userType">
                    <option value="0">--请选择--</option>
                    <option v-for="item in UserType":value="item.UsersInforId">{{item.UsersTypeName}}</option>
                   
                </select>
            </td>
        </tr>
        
 
        <tr>
            <td colspan="2"><input type="button" value="提交" @click="Submit" class="btn btn-success"></td>

  
        </tr>
    </table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { onMounted,ref } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute()

console.log(route.params.uid);


const info=ref({
    id:0,
    name:"",
    sex:true,
    incomes:"",
    birthday:"",
    idCard:"",
    userType:0
})
onMounted(()=>{
    Uinfo()
    showw()
})
const UserType=ref([{
    UsersInforId:0,
    UsersTypeName:""
}])
const Uinfo=()=>{
    axios({
        url:"https://localhost:44366/api/Drom/BanUsersType",
        method:"get"
    })
    .then(res=>{
        UserType.value=res.data
        console.log(UserType.value)
    })
    .catch(err=>{
        console.log(err)
    })   
}
const showw=()=>{
    var s=info.value.idCard.substring(6,14)
    var years=s.substring(0,4)
    var months=s.substring(4,6)
    var days=s.substring(6,8)
    var dates=years+"-"+months+"-"+days
    info.value.birthday=dates
  
    
    
} 



const Submit=()=>{
    if(info.value.name==""){
        alert("请输入真实姓名")
        return
    }
    if(info.value.incomes==""){
        alert('请输入年收入')
        return
    }
    if(info.value.birthday==""){
        alert('请输入出生日期')
        return
    }
    if(info.value.idCard==""){
        alert('请输入身份证')
        return
    }
    
    var lis=/^(\d{6})(18|19|20)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X|x)$/
    if(lis.test(info.value.idCard)==false){
        alert('请输入正确的身份证')
        return
    }
    if(info.value.userType==0){
        alert('请选择用户类型')
        return
    }
    
    axios({
        url:"https://localhost:44366/api/Drom/UserInforcsADD",
        method:"post",
        data:{
            UserLoginId:route.params.uid,
            UserInforcsName:info.value.name,
            UserInforcsSex:info.value.sex,
            UserInforcsscamel:info.value.incomes,
            UserInforcsDate:info.value.birthday,
            UserInforcsIDCarid:info.value.idCard,
            UsersInforId:info.value.userType
        }
    })
    .then(res=>{
        if(res.data>0){
            alert("添加成功")
         
        }else{
            alert("添加失败")
        }
    })
    .catch(err=>{
        console.log(err)
    })
}

</script>